<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('错题记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="printQuestion()">
                    <i class="fa fa-print"></i> 打印试卷
                </a>
                <a class="btn btn-success" onclick="printAnswer()">
                    <i class="fa fa-print"></i> 打印答案
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        var prefix = ctx + "student/question";
        var statusDatas = [[${@dict.getType('sys_data_status')}]];
        $(function() {
            var options = {
                url: prefix + "/wrong/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail/{id}",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "错题记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'null',
                    visible: false
                },
                {
                    field: 'examQuestion.content',
                    title: '试题内容'
                },
                {
                    field: 'wrongCount', 
                    title: '错误数'
                },
                {
                    field: 'totalCount', 
                    title: '总数'
                },
                {
                    field: 'exerciseCount',
                    title: '练习次数'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.examQuestion.id + '\')"><i class="fa fa-eye"></i>预览</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="grasp(\'' + row.id + '\')"><i class="fa fa-paper-plane"></i>掌握</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 掌握
         * @param id
         */
        function grasp(id) {
            $.modal.confirm("点击掌握以后将不再出现在错题库,确认已经掌握了吗？",function() {
                $.operate.post(prefix + "/wrong/grasp", { "id": id });
            });
        }

        /**
         * 打印练习卷
         */
        function printQuestion() {

            var row=$("#bootstrap-table").bootstrapTable('getData');
            var questionIds = "";
            if(row != null && row.length > 0) {
                for (var i = 0; i < row.length; i++) {
                    if(questionIds == ""){
                        questionIds+= row[i].examQuestion.id;
                    }else {
                        questionIds+="," + row[i].examQuestion.id;
                    }
                }
            }
            $.modal.openTab("错题练习卷",prefix+"/printQuestion?questionIds="+questionIds);
        }
        /**
         * 打印答案
         */
        function printAnswer() {
            var row=$("#bootstrap-table").bootstrapTable('getData');
            var questionIds = "";
            if(row != null && row.length > 0) {
                for (var i = 0; i < row.length; i++) {
                    if(questionIds == ""){
                        questionIds+= row[i].examQuestion.id;
                    }else {
                        questionIds+="," + row[i].examQuestion.id;
                    }
                }
            }
            $.modal.openTab("错题练习卷答案",prefix+"/printAnswer?questionIds="+questionIds);

        }
    </script>
</body>
</html>